//
//  AboutUsViewController.m
//  AllFamily
//
//  Created by chirui on 2018/9/12.
//  Copyright © 2018年 Shui. All rights reserved.
//

#import "AboutUsViewController.h"

@interface AboutUsViewController ()

@end

@implementation AboutUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"icon_nav_renter" target:self action:@selector(backBtnClick)];
    [self createUI];
    [self getData];
}

-(void)backBtnClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)createUI {
    self.navigationItem.titleView = [TopLabel withLabelWithLabelText:@"关于我们"];
    
    self.webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, screenW, screenH-64)];
    [self.view addSubview:self.webView];
    self.webView.navigationDelegate = self;
}

#pragma mark - 获取地址
- (void)getData {
    NSDictionary * dic = @{@"type":@"about"};
    [PostNetWorking postNetWorkingStr:[address_url stringByAppendingString:user_agreement_api] andparameters:dic Success:^(id responseObject) {
        if([responseObject[@"code"]intValue] == 200) {
            self.url = responseObject[@"datas"][@"url"];
            [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
        }
        
    } failed:^(NSError *error) {
        [MBProgressHUD showError:@"网络错误" toView:self.view];
    }];
}

#pragma wkwebView navdelegate
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
    // 开始加载网页
    [MBProgressHUD showMessag:nil withDelay:0 toView:self.view withMode:MBProgressHUDModeIndeterminate hideWithDelay:0];
}
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
    // 成功加载网页
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}
- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {
    // 加载网页失败
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    [MBProgressHUD showMessag:@"网络错误" withDelay:0 toView:self.view withMode:MBProgressHUDModeText hideWithDelay:1.5];
}

@end
